const {getHttpCart} = require("../../models/http")
Page({
  data: {
    isChecked:true,
    carts:[]
  },
  onLoad: function (options) {
    getHttpCart({
      success:res=>{
        this.setData({
          carts:res.data
        })
      }
    })
  },
  onItemChange(event){
    this.handleItem("isSelected",event)
  },
  handleCheck(){
    this.setData({
      isChecked:!this.data.isChecked
    })
  },
  onSearch(event){
    console.log(event.detail);
  },
  handleChange(event){
    console.log(event.detail);
  },
  onCount(event){
    this.handleItem("productCount",event)
  },
  handleItem(attr,event){
    var id = event.currentTarget.dataset.id
    var carts = this.data.carts
    var value = event.detail
    var item = carts.find(item=>item.id==id)
    item[attr] = value
    this.setData({
      carts
    })
  },
  onSumChange(event){
    console.log(event.detail)
  },
  onSumChange(event){
    var carts = this.data.carts
    var states = event.detail
    carts.forEach(item=>{
      item.isSelected = states
    })
    this.setData({
      carts
    })
  }
})